﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Customer_Profile.eCardReport.DBDao;
using KVB.Common;
using System.Text;
using DevExpress.Data;
using DevExpress.Web.ASPxGridView;
using Customer_Profile.eCard.DBDao;

namespace Customer_Profile.eCardReport
{
    public partial class ReAgainRatio_Report : System.Web.UI.Page
    {
        DataSet dsResult = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataSet dsProd = ProductDao.getAllProduct("ALL");
                dropProd.DataSource = dsProd;
                dropProd.DataTextField = "procduct_name";
                dropProd.DataValueField = "procduct_code";
                dropProd.DataBind();
                ListItem liAllprod = new ListItem();
                liAllprod.Text = "All";
                liAllprod.Value = "All";
                dropProd.Items.Insert(0, liAllprod);
            }
            lblContent.Text = "";
            BindDataView();
        }

        private void BindDataView()
        {
            try
            {
                string strProdCode = dropProd.SelectedItem.Value;
                dsResult = ReportDao.getAgainedAllData(strProdCode);
                if (dsResult != null && dsResult.Tables.Count > 0)
                {
                    ASPxGridView1.DataSource = dsResult.Tables[0];
                    ASPxGridView1.DataBind();
                }
                ASPxSummaryItem dxCount = ASPxGridView1.TotalSummary[0];
                decimal iCardCount = Convert.ToDecimal(ASPxGridView1.GetTotalSummaryValue(dxCount));
                decimal iAllCount = Convert.ToDecimal(dsResult.Tables[1].Rows[0][0].ToString());
                lblContent.Text += "按卡数计算：" + Math.Round(iCardCount * 100 / iAllCount, 2).ToString() + "%";

                //lbAgainRatio.Text += (iCardCount * 100 / iAllCount).ToString() + "%";
                ASPxSummaryItem dxAmount = ASPxGridView1.TotalSummary[1];
                decimal iCardAmount = Convert.ToDecimal(ASPxGridView1.GetTotalSummaryValue(dxAmount));
                decimal iAllAmount = Convert.ToDecimal(dsResult.Tables[1].Rows[0][1].ToString());
                //lbAgainRatio.Text += "按金额计算：" + (iCardAmount * 100 / iAllAmount).ToString() + "%";
                //if (e.Item == dxAmount)
                lblContent.Text += "&nbsp;&nbsp;按金额计算：" + Math.Round(iCardAmount * 100 / iAllAmount, 2).ToString() + "%";
            }
            catch (Exception ex)
            {
                Log.WriteDefaultLog("Maturity_BindDataView", ex.ToString());
            }
        }
    }
}